package com.crfchina.consumer.eurekaconsumer.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class ConsumerService {

    @Autowired
    private RestTemplate restTemplate;
    @HystrixCommand(fallbackMethod = "addServiceFallback")
    public String addService(){

        //注意使用这个地址,这个地址为控制界面显示的服务显示的名称

      //  return restTemplate.getForEntity("http://compute-service/consumer?a=23&b=23",String.class).getBody();
        return restTemplate.getForEntity("http://COMPUTE-SERVICE/add?a=10&b=20", String.class).getBody();
    }
    public String addServiceFallback() {
        //断路器实现服务降级
        return "error";
    }
}
